package com.zp.demo.service.impl;

import com.zp.demo.repush.enums.RePushType;
import com.zp.demo.repush.service.defined.DefindRePushDbService;
import com.zp.demo.repush.service.defined.DefindSaveLogService;
import com.zp.demo.repush.service.defined.DefindSendEmailService;
import com.zp.demo.repush.service.defined.DefindSendEmsService;
import com.zp.demo.repush.service.impl.BaseRePushServiceImpl;
import com.zp.demo.repush.vo.BaseRePushVo;
import com.zp.demo.repush.vo.RePushStrategyEntity;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @Author 张鹏
 * @Date 2019/1/2 12:32
 */
@Service
@Log4j2
public class RePushServiceImpl extends BaseRePushServiceImpl {

    @Autowired
    private ScheduledTestServie scheduledTestServie;
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;

    @Override
    public BaseRePushVo callbackRepush(BaseRePushVo pushVo, boolean result, Integer remainingCounts,RePushType pushType,String mess) {
        log.debug(pushType.getDesc() + "任务回调：-------------剩余重推次数${remainingCounts}--------------", remainingCounts);
        switch (pushType) {
            case JS_PUSH:
                break;
            case YS_PUSH:
                break;
            case DS_PUSH:
                break;
            default:
                break;
        }

        return pushVo;
    }

    @Override
    public BaseRePushVo saveRepush2DB(BaseRePushVo pushVo, RePushStrategyEntity strategyEntity) {
        log.error("========================保存到数据库===========================");
        return null;
    }
    @Override
    public void save2DbScheduledJob(BaseRePushVo rePushVo, Integer counts) {
        log.info("添加到定时任务");
        List<BaseRePushVo> list = new ArrayList<>();
        list.add(rePushVo);list.add(rePushVo);
        list.add(rePushVo);list.add(rePushVo);
        list.add(rePushVo);list.add(rePushVo);
        list.add(rePushVo);list.add(rePushVo);
        list.add(rePushVo);list.add(rePushVo);
        list.add(rePushVo);list.add(rePushVo);
        scheduledTestServie.add2ScheduledQueue(list, redisTemplate);
    }

    @Override
    public boolean saveLog(BaseRePushVo pushVo) {
        log.debug("未定义保存日志的方法");
        return false;
    }

    @Override
    public boolean sendEmail(BaseRePushVo pushVo) {
        log.debug("未定义发送邮件的方法");
        return false;
    }

    @Override
    public boolean sendEms(BaseRePushVo pushVo) {
        return false;
    }


}
